// DownButton.h: interface for the DownButton class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DOWNBUTTON_H__4EE5DE43_92F3_4187_9395_2622238D0265__INCLUDED_)
#define AFX_DOWNBUTTON_H__4EE5DE43_92F3_4187_9395_2622238D0265__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "awt.h"
#include "awtwin.h"

class AWTWIN_EXPORT DownButton : public AWTCanvas, AWTMouseListener, AWTMouseMotionListener
{
public:
	DownButton();
	virtual ~DownButton();

	CSize getMinimumSize();
	CSize getPreferredSize();

	void addActionListener(AWTActionListener* l) 
		{m_actionListener = AWTEventMulticaster::add(m_actionListener, l);}
  void removeActionListener(AWTActionListener* l) 
		{m_actionListener = AWTEventMulticaster::remove(m_actionListener, l);}
	void processActionEvent(AWTActionEvent* e);
	virtual BOOL isFocusTraversable()
		{return TRUE;}

	virtual void paint(CDC* pDC)
	{
		CBitmap bmp;
		CDC dcMem;

		if (m_bPressed)
		{
			bmp.LoadOEMBitmap(OBM_DNARROWD);
			dcMem.CreateCompatibleDC(pDC);
			dcMem.SelectObject(bmp);
			pDC->BitBlt(0, 0, 16, 16, &dcMem, 0, 0, SRCCOPY);
		}
		else
		{
			bmp.LoadOEMBitmap(OBM_DNARROW);
			dcMem.CreateCompatibleDC(pDC);
			dcMem.SelectObject(bmp);
			pDC->BitBlt(0, 0, 16, 16, &dcMem, 0, 0, SRCCOPY);
		}

		bmp.DeleteObject();
		dcMem.DeleteDC();
	}

	virtual void mouseClicked(AWTMouseEvent* e){}
	virtual void mousePressed(AWTMouseEvent* e)
	{
		m_bPressed = true;
		repaint();
	}
	virtual void mouseReleased(AWTMouseEvent* e)
	{
		CRect rc;
		m_peer->GetClientRect(&rc);
		m_bPressed = false;
		repaint();
		if (rc.PtInRect(e->getPoint()))
		{
			AWTActionEvent e(this, AWTActionEvent::ACTION_PERFORMED, "");
			processActionEvent(&e);
		}
	}
	virtual void mouseEntered(AWTMouseEvent* e){}
	virtual void mouseExited(AWTMouseEvent* e){}

	virtual void mouseDragged(AWTMouseEvent* e)
	{
		CRect rc;
		m_peer->GetClientRect(&rc);
		if (rc.PtInRect(e->getPoint()))
		{
			if (!m_bPressed)
			{
				m_bPressed = true;
				repaint();
			}
		}
		else
		{
			if (m_bPressed)
			{
				m_bPressed = false;
				repaint();
			}
		}
	}
	virtual void mouseMoved(AWTMouseEvent* e){}
	
protected:
  AWTActionListener* m_actionListener;
	bool m_bPressed;
};

#endif // !defined(AFX_DOWNBUTTON_H__4EE5DE43_92F3_4187_9395_2622238D0265__INCLUDED_)
